﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Utils
{
    public class CommonUtil
    {
        /// <summary>
        /// Stream转字符串
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static string StreamToStr(Stream stream) {
            try
            {
                StreamReader reader = new StreamReader(stream,Encoding.UTF8);
                var ret = reader.ReadToEndAsync();
                return ret.Result;
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
            return string.Empty;
        }

        public static byte[] StrToBytes(string str) {
            return StrToBytes(str,"utf-8");
        }

        public static byte[] StrToBytes(string str,string codeName = "utf-8") {
            return System.Text.Encoding.GetEncoding(codeName).GetBytes(str);
        }


    }
}
